//
//  SimpleTabBarController.swift
//  test-ios
//
//  Created by wyz5204 on 2023/6/7.
//

import UIKit

class SimpleTabBarController<T : MVVMBaseViewModel> : UITabBarController{
    
    lazy var viewModel : T = {
        return createViewModel()
    }()
    
    let navigator : MVVMNavigator = MVVMNavigator.shared
    
    init() {
        super.init(nibName: nil, bundle: nil)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        initView(self.view)
        bindViewModel(viewModel)
    }
    
    
    func createViewModel() -> T {
        return SimpleViewModel.shared as! T
    }
    
    public override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        updateView()
    }
    
    func initView(_ contentView : UIView) {
        
    }
    
    func bindViewModel(_ viewModel : T){
        
    }
    
    func updateView(){
        
    }
    
    func registerObserver(selector aSelector: Selector, name aName: NSNotification.Name? = nil, object anObject: Any? = nil){
        NotificationCenter.default.addObserver(self, selector: aSelector, name: aName, object: anObject)
    }
    
    func postMessage(_ aName: NSNotification.Name, object anObject: Any? = nil){
        NotificationCenter.default.post(name: aName , object: anObject)
    }
    
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
    
    
}
